package ldh.im.base.service;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import ldh.common.PageResult;
import ldh.im.base.dao.ImMessageSendDao;
import ldh.im.base.pojo.ImMessageSend;
import ldh.im.base.pojo.where.ImMessageSendWhere;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: ldh
 * @date: 2024-03-21 10:36:17
*/
@Service("imMessageSendService")
public class ImMessageSendService {

	@Resource
	private ImMessageSendDao imMessageSendDao;
	
	@Transactional
	public ImMessageSend insert(ImMessageSend imMessageSend) {
		int n = imMessageSendDao.insert(imMessageSend);
		if (n != 1) {
			throw new RuntimeException("ImMessageSend insert error!");
		}
		return imMessageSend;
	}
	
	@Transactional
	public ImMessageSend insertSelective(ImMessageSend imMessageSend) {
		int n = imMessageSendDao.insert(imMessageSend);
		if (n != 1) {
			throw new RuntimeException("ImMessageSend insertSelective error!");
		}
		return imMessageSend;
	}

	@Transactional
	public ImMessageSend updateById(ImMessageSend imMessageSend) {
		int  n = imMessageSendDao.updateById(imMessageSend);
		if (n != 1) {
			throw new RuntimeException("ImMessageSend update error!");
		}
        return imMessageSend;
     }

	@Transactional
	public ImMessageSend updateNotNullById(ImMessageSend imMessageSend) {
		int  n = imMessageSendDao.updateNotNullById(imMessageSend);
		if (n != 1) {
			throw new RuntimeException("ImMessageSend update error!");
		}
        return imMessageSend;
     }


    @Transactional
    public void deleteById(Long id) {
		int n = imMessageSendDao.deleteById(id);
		if (n != 1) {
			throw new RuntimeException("ImMessageSend delete error!");
		}
    }

	@Transactional(readOnly = true)
	public ImMessageSend getById(Long id) {
		ImMessageSend imMessageSend = imMessageSendDao.getById(id);
		return imMessageSend;
    }
    
	
	@Transactional(readOnly = true)
	public PageResult<ImMessageSend> findByImMessageSendWhere(ImMessageSendWhere imMessageSendWhere) {
		long total = imMessageSendDao.findTotalByImMessageSendWhere(imMessageSendWhere);
		List<ImMessageSend> imageList = new ArrayList<ImMessageSend>();
		if (total > 0) {
			imageList  = imMessageSendDao.findByImMessageSendWhere(imMessageSendWhere);
		}
		
		return new PageResult<ImMessageSend>(imMessageSendWhere, total, imageList);
	}
	
	
}
